package com.nazca.tvremote.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Spinner;

import com.nazca.tvremote.R;
import com.nazca.tvremote.util.Settings;
import com.nazca.tvremote.view.TitleBar;

public class SettingsActivity extends Activity {
	
	private TitleBar mTitleBar;
	
	private SeekBar mTouchpadSensitivityOfLeftRightView;
	private SeekBar mTouchpadSensitivityOfUpDownView;
	private SeekBar mGestureRemoteSpeedView;
	private Spinner mTVRegionView;
	
	private Settings mSettings;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.settings);
		
		mTitleBar = (TitleBar) findViewById(R.id.title_bar);
		mTitleBar.getBackButton().setText(R.string.main_settings);
		mTitleBar.getBackButton().setOnClickListener(new View.OnClickListener(){
			public void onClick(View v) {
				finish();
			}
		});
		
		mTouchpadSensitivityOfLeftRightView = (SeekBar) findViewById(R.id.settings_touchpad_sensitivity_left_right);
		mTouchpadSensitivityOfUpDownView = (SeekBar) findViewById(R.id.settings_touchpad_sensitivity_up_down);
		mGestureRemoteSpeedView = (SeekBar) findViewById(R.id.settings_gesture_remote_speed);
		mTVRegionView = (Spinner) findViewById(R.id.settings_tv_region);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		mSettings = Settings.getSettings(this);
		
		mTouchpadSensitivityOfLeftRightView.setProgress(mSettings.mTouchpadSensitivityOfLeftRight);
		mTouchpadSensitivityOfUpDownView.setProgress(mSettings.mTouchpadSensitivityOfUpDown);
		mGestureRemoteSpeedView.setProgress(mSettings.mGestureRemoteSpeed);
		mTVRegionView.setSelection(mSettings.mTVRegion);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		mSettings.mTouchpadSensitivityOfLeftRight = mTouchpadSensitivityOfLeftRightView.getProgress();
		mSettings.mTouchpadSensitivityOfUpDown = mTouchpadSensitivityOfUpDownView.getProgress();
		mSettings.mGestureRemoteSpeed = mGestureRemoteSpeedView.getProgress();
		mSettings.mTVRegion = mTVRegionView.getSelectedItemPosition();
		mSettings.commit();
	}
	
}